package com.kikcn.demo.controllers;

import com.kikcn.demo.domain.DataObject;
import org.apache.log4j.Logger;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * User: Administrator
 * Date: 2015/7/2
 * Time: 21:11
 */
@Controller
@RequestMapping("/mapper")
public class MapperController {
    public static final Logger logger = Logger.getLogger(MapperController.class);

    @RequestMapping(params = "method=index")
    public String toIndex() {
        return "mapper/index";
    }

    @RequestMapping(params = "method=doMapper")
    public String doMapper(DataObject data) {
        logger.info(data.getName());
        logger.info(data.getNumber());
        logger.info(data.getDate().toString());
        logger.info(data.getUserList().size());
        logger.info(data.getUserSet().size());

        return "mapper/index";
    }

    @InitBinder
    public void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    }
}
